<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<fmt:bundle basename="res">
<head>
    <meta charset="utf-8">
    <title><fmt:message key='lb' /></title>
    <jsp:include page="/WEB-INF/commons/commons-header.jsp" flush="true"/>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">

            <div class="layui-form-item">
                <form name="totalForm" id="totalForm" action="${web_domain}/supplier/banner/list" method="get">

                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='mc' /></label>
                        <div class="layui-input-inline">
                            <input type="text" name="name" placeholder="<fmt:message key='qsrmc' />" value="<c:if test='${params.name !=null}'>${params.name}</c:if>" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='zt' /></label>
                        <div class="layui-input-inline">
                            <select lay-verify="required" name="status">
                                <option value="0" <c:if test="${params.status eq 0}">selected="selected"</c:if>><fmt:message key='qxz' /></option>
                                <option value="1" <c:if test="${params.status eq 1}">selected="selected" </c:if><fmt:message key='xj' /></option>
                                <option value="2" <c:if test="${params.status eq 2}">selected="selected"</c:if>><fmt:message key='shj' /></option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-sm layuiadmin-btn-list" id="search"><i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> <fmt:message key='ss' /></button>
                    </div>
                </form>
            </div>
        </div>

    </div>

    <div class="layui-card">
        <div class="layui-field-box layui-form">

            <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-normal" id="add"><i class="layui-icon">&#xe61f;</i> <fmt:message key='tj' /></a>

            <table class="layui-table" lay-size="sm">
                <thead>
                <th><fmt:message key='mc' /></th>
                <th><fmt:message key='tp' /></th>
                <th><fmt:message key='cjsj' /></th>
                <th><fmt:message key='zt' /></th>
                <th>操作</th>
                </thead>
                <c:forEach items="${page.result}" var="item" varStatus="status">
                    <tr>
                        <td>${item.name }</td>
                        <td><img src="${store_domain}/uploads/${item.image}" style="width:60px;" /></td>
                        <td><fmt:formatDate value="${item.createTime}" pattern="yyyy-MM-dd HH:ss"/></td>
                        <td>
                            <c:choose>
                                <c:when test="${item.status eq 1}"><fmt:message key='xj' /></c:when>
                                <c:when test="${item.status eq 2}"><fmt:message key='shj' /></c:when>
                            </c:choose>
                        </td>
                        <td>
                            <div class="layui-btn-container">

                                    <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs feijin-modify"><fmt:message key='bj' /></a>
                                    <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs feijin-remove"><fmt:message key='sc' /></a>

                                    <c:choose>
                                        <c:when test="${item.status eq 1}">
                                            <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-normal layui-btn-xs feijin-putaway"><fmt:message key='shj' /></a>
                                        </c:when>
                                        <c:otherwise>
                                            <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs feijin-soldout"><fmt:message key='xj' /></a>
                                        </c:otherwise>
                                    </c:choose>


                            </div>
                        </td>
                    </tr>
                </c:forEach>
            </table>
            <jsp:include page="/commons/page.jsp" flush="true"/>
        </div>
    </div>

</div>

<script>

    $(function () {

        //上架店铺海报
        $(".feijin-putaway").click(function () {
            var id = $(this).attr("data-id");
            layer.confirm("<fmt:message key='qrtjsq' />", function () {
                feijin.put({
                    url: "${web_domain}/supplier/banner/enable",
                    data: {id: id}
                });
            });
        });

        //下架店铺海报
        $(".feijin-soldout").click(function () {
            var id = $(this).attr("data-id");
            layer.confirm("<fmt:message key='qrxj' />", function () {
                feijin.put({
                    url: "${web_domain}/supplier/banner/disable",
                    data: {id: id}
                });
            });
        });

        //添加店铺海报
        $("#add").click(function () {
            layer.open({
                type: 2
                , title: '<fmt:message key='tjdphb' />'
                , content: '${web_domain}/supplier/banner/create'
                , maxmin: true
                , area: ['97%', '97%']
                , btn: ['<fmt:message key='bc' />', '<fmt:message key='qx' />']
                , yes: function (index, layero) {
                    var submit = layero.find('iframe').contents().find("#submit");
                    submit.click();
                }
            });
        });

        //编辑
        $(".feijin-modify").click(function () {

            var id = $(this).attr("data-id");

            layer.open({
                type: 2
                , title: '<fmt:message key='bjdphb' />'
                , content: '${web_domain}/supplier/banner/modify?id=' + id
                , maxmin: true
                , area: ['97%', '97%']
                , btn: ['<fmt:message key='bc' />', '<fmt:message key='qx' />']
                , yes: function (index, layero) {
                    var submit = layero.find('iframe').contents().find("#submit");
                    submit.click();
                }
            });
        });


        //删除店铺海报
        $(".feijin-remove").click(function () {
            var id = $(this).attr("data-id");
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.open({
                    type: 0,
                    title: '<fmt:message key='scdphb' />',
                    border: [0],
                    content: '<span class="orange"><fmt:message key='scczqrscgdphbm' /></span>',
                    btn: ['<fmt:message key='sc' />', '<fmt:message key='qx' />'],
                    yes: function () {
                        $.ajax({
                            type: "post",
                            url: "${web_domain}/supplier/banner/remove",
                            dataType: "json",
                            data: {
                                "id": id,
                                "_method": "delete"
                            },
                            success: function (data) {
                                location.reload();
                            }
                        });
                    },
                    no: function () {
                        layer.close(index);
                    }
                });
            });
        });

    });
</script>
</body>
</fmt:bundle>
</html>
